{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "简单实用的pandas技巧：如何将内存占用降低90%\n",
    "\n",
    "https://mp.weixin.qq.com/s?__biz=MzA3ODYwNDkzOQ==&mid=2659066564&idx=1&sn=0bcf932a20fc24546604020c0ee0a001&chksm=84cabd20b3bd34360894071f4c12bd36f2dc764c3e8c672cc52cdec3bac4ab609b6c6542afe7&scene=132#wechat_redirect"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "d:\\ProgramData\\Anaconda3\\lib\\site-packages\\numpy\\_distributor_init.py:32: UserWarning: loaded more than 1 DLL from .libs:\n",
      "d:\\ProgramData\\Anaconda3\\lib\\site-packages\\numpy\\.libs\\libopenblas.NOIJJG62EMASZI6NYURL6JBKM4EVBGM7.gfortran-win_amd64.dll\n",
      "d:\\ProgramData\\Anaconda3\\lib\\site-packages\\numpy\\.libs\\libopenblas.XWYDX2IKJW2NMTWSFYNGFUWKQU3LYTCZ.gfortran-win_amd64.dll\n",
      "  stacklevel=1)\n",
      "d:\\ProgramData\\Anaconda3\\lib\\site-packages\\IPython\\core\\interactiveshell.py:3418: DtypeWarning: Columns (12,13,14,15,19,20,81,83,85,87,93,94,95,96,97,98,99,100,105,106,108,109,111,112,114,115,117,118,120,121,123,124,126,127,129,130,132,133,135,136,138,139,141,142,144,145,147,148,150,151,153,154,156,157,160) have mixed types.Specify dtype option on import or set low_memory=False.\n",
      "  exec(code_obj, self.user_global_ns, self.user_ns)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>date</th>\n",
       "      <th>number_of_game</th>\n",
       "      <th>day_of_week</th>\n",
       "      <th>v_name</th>\n",
       "      <th>v_league</th>\n",
       "      <th>v_game_number</th>\n",
       "      <th>h_name</th>\n",
       "      <th>h_league</th>\n",
       "      <th>h_game_number</th>\n",
       "      <th>v_score</th>\n",
       "      <th>...</th>\n",
       "      <th>h_player_7_name</th>\n",
       "      <th>h_player_7_def_pos</th>\n",
       "      <th>h_player_8_id</th>\n",
       "      <th>h_player_8_name</th>\n",
       "      <th>h_player_8_def_pos</th>\n",
       "      <th>h_player_9_id</th>\n",
       "      <th>h_player_9_name</th>\n",
       "      <th>h_player_9_def_pos</th>\n",
       "      <th>additional_info</th>\n",
       "      <th>acquisition_info</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>18710504</td>\n",
       "      <td>0</td>\n",
       "      <td>Thu</td>\n",
       "      <td>CL1</td>\n",
       "      <td>na</td>\n",
       "      <td>1</td>\n",
       "      <td>FW1</td>\n",
       "      <td>na</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>Ed Mincher</td>\n",
       "      <td>7.0</td>\n",
       "      <td>mcdej101</td>\n",
       "      <td>James McDermott</td>\n",
       "      <td>8.0</td>\n",
       "      <td>kellb105</td>\n",
       "      <td>Bill Kelly</td>\n",
       "      <td>9.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Y</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>18710505</td>\n",
       "      <td>0</td>\n",
       "      <td>Fri</td>\n",
       "      <td>BS1</td>\n",
       "      <td>na</td>\n",
       "      <td>1</td>\n",
       "      <td>WS3</td>\n",
       "      <td>na</td>\n",
       "      <td>1</td>\n",
       "      <td>20</td>\n",
       "      <td>...</td>\n",
       "      <td>Asa Brainard</td>\n",
       "      <td>1.0</td>\n",
       "      <td>burrh101</td>\n",
       "      <td>Henry Burroughs</td>\n",
       "      <td>9.0</td>\n",
       "      <td>berth101</td>\n",
       "      <td>Henry Berthrong</td>\n",
       "      <td>8.0</td>\n",
       "      <td>HTBF</td>\n",
       "      <td>Y</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>18710506</td>\n",
       "      <td>0</td>\n",
       "      <td>Sat</td>\n",
       "      <td>CL1</td>\n",
       "      <td>na</td>\n",
       "      <td>2</td>\n",
       "      <td>RC1</td>\n",
       "      <td>na</td>\n",
       "      <td>1</td>\n",
       "      <td>12</td>\n",
       "      <td>...</td>\n",
       "      <td>Pony Sager</td>\n",
       "      <td>6.0</td>\n",
       "      <td>birdg101</td>\n",
       "      <td>George Bird</td>\n",
       "      <td>7.0</td>\n",
       "      <td>stirg101</td>\n",
       "      <td>Gat Stires</td>\n",
       "      <td>9.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Y</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>18710508</td>\n",
       "      <td>0</td>\n",
       "      <td>Mon</td>\n",
       "      <td>CL1</td>\n",
       "      <td>na</td>\n",
       "      <td>3</td>\n",
       "      <td>CH1</td>\n",
       "      <td>na</td>\n",
       "      <td>1</td>\n",
       "      <td>12</td>\n",
       "      <td>...</td>\n",
       "      <td>Ed Duffy</td>\n",
       "      <td>6.0</td>\n",
       "      <td>pinke101</td>\n",
       "      <td>Ed Pinkham</td>\n",
       "      <td>5.0</td>\n",
       "      <td>zettg101</td>\n",
       "      <td>George Zettlein</td>\n",
       "      <td>1.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Y</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>18710509</td>\n",
       "      <td>0</td>\n",
       "      <td>Tue</td>\n",
       "      <td>BS1</td>\n",
       "      <td>na</td>\n",
       "      <td>2</td>\n",
       "      <td>TRO</td>\n",
       "      <td>na</td>\n",
       "      <td>1</td>\n",
       "      <td>9</td>\n",
       "      <td>...</td>\n",
       "      <td>Steve Bellan</td>\n",
       "      <td>5.0</td>\n",
       "      <td>pikel101</td>\n",
       "      <td>Lip Pike</td>\n",
       "      <td>3.0</td>\n",
       "      <td>cravb101</td>\n",
       "      <td>Bill Craver</td>\n",
       "      <td>6.0</td>\n",
       "      <td>HTBF</td>\n",
       "      <td>Y</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 161 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       date  number_of_game day_of_week v_name v_league  v_game_number h_name  \\\n",
       "0  18710504               0         Thu    CL1       na              1    FW1   \n",
       "1  18710505               0         Fri    BS1       na              1    WS3   \n",
       "2  18710506               0         Sat    CL1       na              2    RC1   \n",
       "3  18710508               0         Mon    CL1       na              3    CH1   \n",
       "4  18710509               0         Tue    BS1       na              2    TRO   \n",
       "\n",
       "  h_league  h_game_number  v_score  ...  h_player_7_name  h_player_7_def_pos  \\\n",
       "0       na              1        0  ...       Ed Mincher                 7.0   \n",
       "1       na              1       20  ...     Asa Brainard                 1.0   \n",
       "2       na              1       12  ...       Pony Sager                 6.0   \n",
       "3       na              1       12  ...         Ed Duffy                 6.0   \n",
       "4       na              1        9  ...     Steve Bellan                 5.0   \n",
       "\n",
       "  h_player_8_id  h_player_8_name h_player_8_def_pos h_player_9_id  \\\n",
       "0      mcdej101  James McDermott                8.0      kellb105   \n",
       "1      burrh101  Henry Burroughs                9.0      berth101   \n",
       "2      birdg101      George Bird                7.0      stirg101   \n",
       "3      pinke101       Ed Pinkham                5.0      zettg101   \n",
       "4      pikel101         Lip Pike                3.0      cravb101   \n",
       "\n",
       "   h_player_9_name  h_player_9_def_pos  additional_info acquisition_info  \n",
       "0       Bill Kelly                 9.0              NaN                Y  \n",
       "1  Henry Berthrong                 8.0             HTBF                Y  \n",
       "2       Gat Stires                 9.0              NaN                Y  \n",
       "3  George Zettlein                 1.0              NaN                Y  \n",
       "4      Bill Craver                 6.0             HTBF                Y  \n",
       "\n",
       "[5 rows x 161 columns]"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "\n",
    "gl = pd.read_csv('game_logs.csv')\n",
    "gl.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 171907 entries, 0 to 171906\n",
      "Columns: 161 entries, date to acquisition_info\n",
      "dtypes: float64(77), int64(6), object(78)\n",
      "memory usage: 859.4 MB\n"
     ]
    }
   ],
   "source": [
    "gl.info(memory_usage='deep')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.9"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
